package com.dc.system.controller;

import com.dc.common.aop.LogAop;
import com.dc.common.aop.LoginAop;
import com.dc.common.constants.ConstantsCommon;
import com.dc.common.controller.BaseController;
import com.dc.common.em.EnumOperationModule;
import com.dc.common.model.BaseModel;
import com.dc.system.model.SysLoginlog;
import com.dc.system.model.SysOperationlog;
import com.dc.system.service.LogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/system/log")
@Api(description = "日志相关接口")
public class LogController extends BaseController {

    @Autowired
    private LogService logService;

    @LoginAop
    @LogAop(module = EnumOperationModule.No11105, type = ConstantsCommon.FUN_SEARCH )
    @ApiOperation(value = "列表/高级查询登录日志", response = SysLoginlog.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "rows", value = "行数", required = true, dataType = "Integer", paramType = "query"),
            @ApiImplicitParam(name = "key", value = "关键字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "string", paramType = "query")
    })
    @PostMapping("/getLoginlogs")
    public BaseModel getLoginlogs(BaseModel baseModel, String startTime, String endTime) throws Exception {
        return logService.getLoginlogs(baseModel,startTime,endTime);
    }

    @LoginAop
    @LogAop(module = EnumOperationModule.No11104, type = ConstantsCommon.FUN_SEARCH )
    @ApiOperation(value = "列表/高级查询操作日志", response = SysOperationlog.class)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "rows", value = "行数", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "key", value = "关键字", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "startTime", value = "开始时间", dataType = "string", paramType = "query"),
            @ApiImplicitParam(name = "endTime", value = "结束时间", dataType = "string", paramType = "query")
    })
    @PostMapping("/getOperationlogs")
    public BaseModel getOperationlogs(BaseModel baseModel, String startTime, String endTime) throws Exception {
        return logService.getOperationlogs(baseModel,startTime,endTime);
    }
}
